@extends("admin::layouts.master")
@section("content")

    <div class="col-lg-12">
        <div class="card card-table">
            <div class="card-header">
                分类管理
                <div class="mt-2">

                    <button type="button" class="btn btn-primary">
                        分类列表
                    </button>
                    <button data-toggle="modal" data-target="#shop" type="button" class="btn btn-primary">
                        添加分类
                    </button>


                    @component("components.modal",['title'=>'添加用户','url'=>'/shop/category','id'=>'shop','method'=>'POST'])

                        <div class="form-group">
                            <label>分类名称</label>
                            <input type="text" placeholder="请输入商品名称" name="shopname" class="form-control">
                        </div>
                        <div class="form-group">
                            <div class="col-md-12">
                                <label>请选择分类</label>
                                <select class="form-control" name="pid">
                                    <option value="0"  selected="">顶级分类</option>
                                    {{--注意这点，怎么弄的--}}
                                    @foreach($cate as $v)
                                    <option value="{{$v['id']}}"  selected="">{{$v['shopname']}}</option>
                                    @endforeach

                                </select>
                            </div>
                        </div>

                    @endcomponent




                </div>
            </div>
            <div class="card-body">
                <table class="table table-sm table-striped">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>商品名称</th>
                        <th>所属分类</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>

                    @foreach($gory as $v)
                        <tr>
                            <td>{{$v['id']}}</td>
                            <td>{{$v['shopname']}}</td>

                            <td>{{isset($v->fenlei->shopname)?$v->fenlei->shopname:'顶级分类'}}</td>

                            <td>{{$v['created_at']}}</td>
                            <td>
                                <button data-toggle="modal" data-target="#editshop{{$v['id']}}" type='button' class="btn btn-primary">
                                    编辑
                                </button>


                                <form style="display: inline" action="/shop/category/{{$v['id']}}" method="post">
                                    @csrf
                                    @method('DELETE')
                                    <button  class="btn btn-success">
                                        删除
                                    </button>
                                </form>




                                @component("components.modal",['title'=>'编辑用户','url'=>'/shop/category/'.$v['id'],'id'=>'editshop'.$v['id'],'method'=>'PUT'])

                                    <div class="form-group">
                                        <label>分类名称</label>
                                        <input type="text" placeholder="请输入商品名称" name="shopname" class="form-control" value="{{$v['shopname']}}">
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-12">
                                            <label>所属分类</label>
                                            <select class="form-control" name="pid">
                                                @if($v['pid']==0)

                                                <option value="0">顶级分类</option>


                                                @else

                                                    <option value="0">顶级分类</option>

                                                @endif
                                                {{--注意这点，怎么弄的,键名键值--}}
                                                @foreach($cate as $vv)
                                                    @if($v['pid']==$vv['id'])
                                                    <option value="{{$vv['id']}}" selected>

                                                            {{$vv['shopname']}}

                                                    </option>
                                                        @else

                                                            <option value="{{$vv['id']}}">

                                                                {{$vv['shopname']}}

                                                            </option>

                                                        @endif
                                                @endforeach

                                            </select>
                                        </div>
                                    </div>

                                @endcomponent

                            </td>

                            @endforeach

                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        {{$gory->links()}}
    </div>
@stop